﻿using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;

namespace TrainingWorkshop.DAL
{
    /// <summary>
    /// Author: Sissi Zeng
    /// Date:2012 08-08 15:00
    /// Read and Write from/into Table Teacher
    /// </summary>
    public class TeacherRepository_Sql:IRepository
    {
        private SqlConnection sqlConnection;

        public TeacherRepository_Sql(SqlConnection sqlConnection)
        {
            // TODO: Complete member initialization
            this.sqlConnection = sqlConnection;
        }


        public   TResualt Select<TResualt, T>(T t)
        {

            TResualt result = default(TResualt);
            List<Model.Teacher> teacherList = new List<Model.Teacher>();

            
            using (SqlConnection conn = new SqlConnection(SQLHelper.ConnectionStringProjectb))
            {
                conn.Open();
                string selectStatement = "select * from Teacher";
                SqlDataAdapter da = new SqlDataAdapter(selectStatement, conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                //convert to list
                foreach (DataRow row in dt.Rows)
                {
                    Model.Teacher teacher = new Model.Teacher(Convert.ToInt32(row[0]), row[1].ToString().Trim(), row[2].ToString().Trim(), Convert.ToInt32(row[3]));
                    teacherList.Add(teacher);
                }
            }
            result = (TResualt)(object)teacherList;
            return result;
        }

       public  void SelectAll() {
           Console.Write("Insert");
        }


    }
}
